// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Cluster
{
	public sealed class ClusterAllocationExplainRequestParameters : RequestParameters<ClusterAllocationExplainRequestParameters>
	{
		[JsonIgnore]
		public bool? IncludeDiskInfo { get => Q<bool?>("include_disk_info"); set => Q("include_disk_info", value); }

		[JsonIgnore]
		public bool? IncludeYesDecisions { get => Q<bool?>("include_yes_decisions"); set => Q("include_yes_decisions", value); }
	}

	public sealed partial class ClusterAllocationExplainRequest : PlainRequestBase<ClusterAllocationExplainRequestParameters>
	{
		internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterAllocationExplain;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public bool? IncludeDiskInfo { get => Q<bool?>("include_disk_info"); set => Q("include_disk_info", value); }

		[JsonIgnore]
		public bool? IncludeYesDecisions { get => Q<bool?>("include_yes_decisions"); set => Q("include_yes_decisions", value); }

		[JsonInclude]
		[JsonPropertyName("current_node")]
		public string? CurrentNode { get; set; }

		[JsonInclude]
		[JsonPropertyName("index")]
		public Elastic.Clients.Elasticsearch.IndexName? Index { get; set; }

		[JsonInclude]
		[JsonPropertyName("primary")]
		public bool? Primary { get; set; }

		[JsonInclude]
		[JsonPropertyName("shard")]
		public int? Shard { get; set; }
	}

	public sealed partial class ClusterAllocationExplainRequestDescriptor : RequestDescriptorBase<ClusterAllocationExplainRequestDescriptor, ClusterAllocationExplainRequestParameters>
	{
		internal ClusterAllocationExplainRequestDescriptor(Action<ClusterAllocationExplainRequestDescriptor> configure) => configure.Invoke(this);
		public ClusterAllocationExplainRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterAllocationExplain;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public ClusterAllocationExplainRequestDescriptor IncludeDiskInfo(bool? includeDiskInfo = true) => Qs("include_disk_info", includeDiskInfo);
		public ClusterAllocationExplainRequestDescriptor IncludeYesDecisions(bool? includeYesDecisions = true) => Qs("include_yes_decisions", includeYesDecisions);
		private string? CurrentNodeValue { get; set; }

		private Elastic.Clients.Elasticsearch.IndexName? IndexValue { get; set; }

		private bool? PrimaryValue { get; set; }

		private int? ShardValue { get; set; }

		public ClusterAllocationExplainRequestDescriptor CurrentNode(string? currentNode)
		{
			CurrentNodeValue = currentNode;
			return Self;
		}

		public ClusterAllocationExplainRequestDescriptor Index(Elastic.Clients.Elasticsearch.IndexName? index)
		{
			IndexValue = index;
			return Self;
		}

		public ClusterAllocationExplainRequestDescriptor Primary(bool? primary = true)
		{
			PrimaryValue = primary;
			return Self;
		}

		public ClusterAllocationExplainRequestDescriptor Shard(int? shard)
		{
			ShardValue = shard;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(CurrentNodeValue))
			{
				writer.WritePropertyName("current_node");
				writer.WriteStringValue(CurrentNodeValue);
			}

			if (IndexValue is not null)
			{
				writer.WritePropertyName("index");
				JsonSerializer.Serialize(writer, IndexValue, options);
			}

			if (PrimaryValue.HasValue)
			{
				writer.WritePropertyName("primary");
				writer.WriteBooleanValue(PrimaryValue.Value);
			}

			if (ShardValue.HasValue)
			{
				writer.WritePropertyName("shard");
				writer.WriteNumberValue(ShardValue.Value);
			}

			writer.WriteEndObject();
		}
	}
}